package com.aop;

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by Administrator on 2016/9/22.
 */
public class Client {
    public static void main(String[] args) {
        ProxyFactory proxyFactory = new ProxyFactory();         //创建工厂
        proxyFactory.setTarget(new GreetingImpl());             // 射入目标对象
//        proxyFactory.addAdvice(new GreetingBeforeAdvice());     // 添加前置
//        proxyFactory.addAdvice(new GreetingAfterAdvice());      //  添加后置

//        proxyFactory.addAdvice(new GreetingBeforAndAfterAdvice());//

        proxyFactory.addAdvice(new GreetingAroundAdvice());//

        Greeting greeting = (Greeting)proxyFactory.getProxy(); // 从代理工厂中获取代理
        greeting.say("liam");                                   // 调用代理的方法


        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        Greeting greeting1 = (Greeting) context.getBean("greetingProxy");
        greeting1.say("jack");
    }
}
